<div class="form-container">
	<form id="form">
		<table class="tableform">
			<tr>
				<th style="width:70px;">父级目录：</th>
				<td colspan="4">
					<input id="catalog" name="pid" class="easyui-validatebox" type="text" style="width: 282px; height:25px;" />
				 	<a onClick="$catalog.combotree('setValue', '');$category.combobox('setValue', 'catalog');" class="easyui-linkbutton ml-3" data-options="plain: true"><i class='fa fa-remove fa-120 pt-5 pb-4 icon-red'></i></a>
				 	<a onClick="$catalog.combotree('reload')" class="easyui-linkbutton ml-3" data-options="plain: true"><i class='fa fa-refresh fa-120 pt-5 pb-4 icon-green'></i></a>
				</td>
			</tr>
			<tr>
				<th>菜单名称：</th>
				<td style="position: relative;">
					<input name="fullName" class="easyui-validatebox" type="text" data-options="required: true" style="float:left;width:180px;"/>
				</td>
				<th style="width:70px;">唯一编码：</th>
				<td colspan="4">
					<input name="code" class="easyui-validatebox" type="text" data-options="required: true" style="width:180px;"/>
				</td>
			</tr>
			<tr>
				<th>菜单分类：</th>
				<td>
					<input id="category" name="category" style="width:188px;height:25px;">
				</td>
				<th>连接目标：</th>
				<td>
					<input id="target" name="target" style="width:188px;height:25px;">
				</td>
			</tr>
			<tr id="location">
				<th>访问地址：</th>
				<td colspan="4">
					<input name="location" class="easyui-validatebox" type="text" style="width:95.3%;" />
				</td>
			</tr>
			<tr id="iconCls" style="display:none;">
				<th>iCon图标：</th>
				<td colspan="4">
					<input name="iconCls" class="easyui-validatebox" type="text" style="width:95.6%;" />
				</td>
			</tr>
			<tr>
				<th>层级：</th>
				<td>
					<input name="level" class="easyui-numberbox" type="text" data-options="prompt: '不填写则为默认排序'" style="width:186px;" />
				</td>
				<th>排序：</th>
				<td>
					<input name="sortCode" class="easyui-numberbox" type="text" data-options="prompt: '不填写则为默认排序'" style="width:186px;" />
				</td>
			</tr>
			<tr>
				<th>是否展开：</th>
				<td>
					<div id="icheck">
						<input id="i1" type="radio" name="isexpand" value="1" checked="checked">
						<label class="irl" for="i1">展开</label>　
						<input id="i2" type="radio" name="isexpand" value="-1">
						<label class="irl" for="i2">折叠</label>　
					</div>
				</td>
				<th>是否有效：</th>
				<td>
					<div id="icheck">
						<input id="disabled1" type="radio" name="enabled" value="1" checked="checked">
						<label class="irl" for="disabled1">有效</label>　
						<input id="disabled2" type="radio" name="enabled" value="-1">
						<label class="irl" for="disabled2">无效</label>　
					</div>
				</td>
			</tr>
			<tr>
				<th>选项：</th>
				<td colspan="4" style="position: relative;">
					<div id="icheck" class="defaultSelect" style="position: absolute;left:5px;top:5px;">
						<input id="input-2" type="checkbox" name="defaultSelect"> <label class="irl" for="input-2">默认选中</label>
					</div>
				</td>
			</tr>
			<tr style="display:none">
				<td>
					<input type="hidden" name="id" value="${id!}">
					<input type="hidden" id="checkId">
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	var form_url = "${ctx}/manager/system/menu/add", id = "${id!}", 
	$target, $category, $catalog, href, defaultSelect = ".defaultSelect" ;
	$(function(){
		$('#icheck input').iCheck({
			checkboxClass: 'icheckbox_minimal-blue',
			radioClass: 'iradio_square-blue'
	   	});
	   	
	   	$category = $("#category").combobox({
			textField: 'value', valueField: 'label', value: 'page',
			data: [{ label: 'catalog', value: '目录' },{ label: 'page', value: '页面' }],
			panelHeight:'auto', editable:false, autoShowPanel: true,
			onSelect: function(node){
				if("catalog" == node.label) {
					$target.combobox("setValue", "click");
					$("input[name=location]").val("");
					$("#location").hide();
					$("#iconCls").show();
					$(defaultSelect).show();
				} else {
					$target.combobox("setValue", "iframe");
					$("input[name=location]").val(href);
					$("#iconCls").hide();
					$("#location").show();
					$(defaultSelect).hide();
					$('input[name=defaultSelect]').iCheck('uncheck');
				}
			},
            onLoadSuccess: function(node,data) {
				$(defaultSelect).hide();
			}
		}) ;
		
	   	$target = $("#target").combobox({
			textField: 'label', valueField: 'label', value: 'iframe',
			data: [{ label: 'iframe', value: 'iframe' },{ label: 'click', value: 'click' }],
			panelHeight:'auto', editable:false, autoShowPanel: true,
			onSelect: function(node){
			}
		}) ;
		
		
		$catalog = $("#catalog").combotree({
			url: "${ctx}/manager/system/menu/findMenuChildByCatalog", method: "GET",
			idFiled:'pid', editable: false, required:false, lines:true, autoShowPanel: false
		});
		
		
		
		if(undefined != id && "" != id) {
			form_url = "${ctx}/manager/system/menu/update" ;
			$.ajax({
				type: "GET", dataType: "JSON",
				url: "${ctx}/manager/system/menu/get/"+id,
				success: function(result) {
					
					$("input[name=enabled][value="+result.enabled+"]").iCheck('check') ;
					$("input[name=isexpand][value="+result.isexpand+"]").iCheck('check') ;
					if("catalog" == result.category) {
						$("#location").hide();
						$("#iconCls").show();
						$(defaultSelect).show();
						if(result.defaultSelect) {
							$("input[name=defaultSelect]").iCheck('check') ;
						}
					} else {
						$("#iconCls").hide();
						$("#location").show();
						$(defaultSelect).hide();
						$('input[name=defaultSelect]').iCheck('uncheck');
					}
					
					href = result.location;//编辑模式下保持location的值，避免吴删除
					$("#form").form("load", result);
				},
				complete: function(XMLHttpRequest, textStatus){},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					$.easyui.loaded();
					if(XMLHttpRequest.status == 403) {
						$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
					} else {
						$.messager.alert("错误", "发生未知错误", "error");
					}
				}
			});
		}
		
		
	});
	
	//提交表单数据
	var submitNow = function($d, $tg, flag) {
		var data = $("#form").form("getData");
		if(data.category == "page") {
			if(data.pid == "") {$.easyui.loaded();$.messager.alert("错误", "分类为页面，则必须指定父级关系", "warning");return;}
		}
		
		$.post(form_url, data, function(result) {
			if (result.status) {
				$tg.treegrid('reload');alertify.success(result.message);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.message, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $tg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $tg, flag) ;
		}
	};
</script>

